package com.mydemo.springlearning.functions.swagger2.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @desc: Swagger配置
 * @author: YanMingXin
 * @create: 2021/8/2-14:34
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 配置Docket的bean
     *
     * @return
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mydemo.springlearning.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    /**
     * 配置文档信息（apiInfo）
     *
     * @return
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact("Mr.YanMingXin", "https://blog.***.net/Mr_YanMingXin", "联系人邮箱/博客");
        /**
         * 参数1：标题
         * 参数2：描述
         * 参数3：版本
         * 参数4：组织链接
         * 参数5：联系人信息
         * 参数6：许可
         * 参数7：许可连接
         * 参数8：扩展
         */
        return new ApiInfo(
                "Spring Boot 整合 Swagger",
                "学习Swagger,Spring Boot 整合 Swagger",
                "v1.0",
                "https://blog.***.net/Mr_YanMingXin",
                contact,
                "Apache 2.0 许可",
                "https://blog.***.net/Mr_YanMingXin",
                new ArrayList<>()
        );
    }
}